from datetime import datetime
from sqlmodel import Field, SQLModel, Index
from typing import Optional

class PartnerToken(SQLModel, table=True):
    """合作伙伴令牌数据库模型"""
    __tablename__ = "t_partner_token"  # 对应数据库表名

    # 索引定义（优化查询性能）
    __table_args__ = (
        Index("idx_uid", "uid", info="用户UID索引"),
    )

    id: Optional[int] = Field(default=None, primary_key=True, index=True, description="主键，自增ID")
    uid: int = Field(default=0, index=True, description="用户UID")
    partner: int = Field(default=0, description="合作方")
    accessToken: str = Field(default="", description="用户合作方Token")
    status: int = Field(default=0, description="状态")
    expiresAt: datetime = Field(default_factory=datetime.now, description="过期时间")
    createdAt: datetime = Field(default_factory=datetime.now, description="创建时间")
    updatedAt: datetime = Field(default_factory=datetime.now, sa_column_kwargs={"onupdate": datetime.now}, description="更新时间")
